﻿using Estsh.Core.Model.EnumUtil;
using Estsh.Core.Model.Extend.IFModels;
using Estsh.Core.Models;
using Estsh.Core.Quartz.BaseService;
using Estsh.Core.Util;
using Estsh.Core.Wms.IRepositories;

namespace Estsh.Core.Wms.Jobs
{
    /// <summary>
    /// 生成工单
    /// </summary>
    public class JitPullWordJob : IJobService
    {
        private readonly IPullingRepository pullRepository;
        private readonly IMoveOrderRepository moveOrderRepository;



        public JitPullWordJob(IPullingRepository _pullGroupRepository,
            IMoveOrderRepository _moveOrderRepository)
        {
            this.pullRepository = _pullGroupRepository;
            this.moveOrderRepository = _moveOrderRepository;

        }

        public string ExecuteService(string parameter)
        {
            try
            {

				

				List<MesWmsWorkOrder_Extend> mesWmsWorks = pullRepository.GetProductionQueueExtendInfo();
                 bool isWork=false;
                if (mesWmsWorks.Count > 0)
                {
                    isWork = pullRepository.InsertProductionQueueExtendInfo(mesWmsWorks); //"待处理的JIT生产队列！";
                }
                else {
                    return "没有新的工单数据！";
                }

                if (isWork)
                {
                    return "生成工单成功！";
                }
                else {
                    return "生成工单失败！";
                }

            }
            catch (Exception ex) 
            {
                LogHelper.Error("生成工单失败！" + ex);
                return "生成工单失败！" + ex.Message;
            }
            
        }
    }
}
